package com.ruoyi.web.publish.resume.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.publish.resume.domain.Resume;
import com.ruoyi.web.publish.resume.service.IResumeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的简历Controller
 *
 * @author liuyu
 * @date 2021-08-24
 */
@RestController
@RequestMapping("/publish/resume")
public class ResumeController extends BaseController {
    @Autowired
    private IResumeService resumeService;

    /**
     * 查询我的简历列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Resume resume) {
        startPage();
        List<Resume> list = resumeService.selectResumeList(resume);
        return getDataTable(list);
    }

    /**
     * 导出我的简历列表
     */
    @Log(title = "我的简历", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Resume resume) {
        List<Resume> list = resumeService.selectResumeList(resume);
        ExcelUtil<Resume> util = new ExcelUtil<Resume>(Resume.class);
        return util.exportExcel(list, "我的简历数据");
    }

    /**
     * 获取我的简历详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(resumeService.selectResumeById(id));
    }

    /**
     * 获取所属人的简历详细信息
     */
    @GetMapping(value = "getResumeToBelongs/{id}")
    public AjaxResult getResumeToBelongs(@PathVariable("id") Long userId) {
        return AjaxResult.success(resumeService.getResumeToBelongs(userId));
    }

    /**
     * 获取我的简历详细信息
     */
    @GetMapping(value = "/getMyResume")
    public AjaxResult getMyResume() {
        return AjaxResult.success(resumeService.getMyResume());
    }


    /**
     * 新增我的简历
     */
    @Log(title = "我的简历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Resume resume) {
        return toAjax(resumeService.insertResume(resume));
    }


    /**
     * 保存我的简历
     */
    @Log(title = "我的简历", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Resume resume) {
        if (null == resume || null == resume.getId()) {
            return toAjax(resumeService.insertResume(resume));
        } else {
            return toAjax(resumeService.updateResume(resume));
        }
    }

    /**
     * 修改我的简历
     */
    @Log(title = "我的简历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Resume resume) {
        return toAjax(resumeService.updateResume(resume));
    }

    /**
     * 删除我的简历
     */
    @Log(title = "我的简历", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(resumeService.deleteResumeByIds(ids));
    }
}
